﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DnPakExplorer.Controls;

namespace DnPakExplorer.Forms {
	public partial class SkillPanelForm : FormBase {

		private Character mCharacter;

		public SkillPanelForm(Character character) {
			InitializeComponent();
			mCharacter = character;
			listGridView1.OnGridHover = OnItemHover;
			character.SkillNanel.OnSkillItemChanged += SkillNanel_OnSkillItemChanged;
			SkillNanel_OnSkillItemChanged();
		}

		void SkillNanel_OnSkillItemChanged() {
			listGridView1.SetAdapter(new SkillListAdapter(mCharacter.SkillNanel));
			listGridView1.Refresh();
		}

		public void OnItemHover(int row, int column) {
			SkillPanel panel = mCharacter.SkillNanel;
			if (row >=0 && column==0 && panel[row] != null) {
				Skill skill = panel[row];
				listGridView1.Capture = true;
				InfoOverlayForm.ShowItem(skill);
			} else {
				InfoOverlayForm.HideItem();
				listGridView1.Capture = false;
			}
		}

		class SkillListAdapter : ListGridAdapter {
			private SkillPanel mPanel;

			public SkillListAdapter(SkillPanel panel) {
				mPanel = panel;
			}

			public override int RowCount {
				get { return mPanel.SkillCount; }
			}

			public override int ColumnCount {
				get { return 2; }
			}

			public override void GetTopLeft(Grid grid) {
				grid.text = "";
			}

			public override void GetGridData(int row, int column, Grid grid) {
				grid.text = "";
				Skill skill = mPanel[row];
				switch (column) {
				case 1:
					grid.text = skill.Name;
					break;
				case 2:
					grid.text = skill.Level.ToString();
					break;
				}
				
			}

			public override void GetRowHeader(int row, Grid grid) {
				grid.text = row.ToString();
			}

			public override void GetColumnHeader(int column, Grid grid) {
				grid.text = "";
				switch (column) {
				case 0:
					grid.text = "技能名";
					break;
				case 1:
					grid.text = "等级";
					break;
				}
				
			}
		}
	}
}
